var scene,  //场景  可以添加物体
  camera,   //摄像机
  renderer; //渲染器


// 等待依赖类库加载完成

window.onload = function () {

  // 实例化对象
  scene = new THREE.Scene();

  // 命名空间；不污染全局
  // static
  camera = new THREE.PerspectiveCamera(90,
    document.body.clientWidth / document.body.clientHeight,
    0.1,
    1000
  );
  // https://img1.baidu.com/it/u=237742676,3963391586&fm=26&fmt=auto&gp=0.jpg


  // 设置摄像机位置
  camera.position.set(0, 0, 0.01)


  // WebGL    渲染3D 可以使用渲染加速
  renderer = new THREE.WebGLRenderer();

  renderer.setSize(
    document.body.clientWidth,
    document.body.clientHeight
  );


  console.log(document.body.clientHeight)


  document.getElementById("container").appendChild(renderer.domElement);
  var controls = new THREE.OrbitControls(camera, renderer.domElement);
  
  useFang()

  loop()

}

function useFang() {


  var materials = [];


  var texture_left = new THREE.TextureLoader().load('./images/scene_left.jpeg');
  materials.push(new THREE.MeshBasicMaterial({ map: texture_left }));

  var texture_right = new THREE.TextureLoader().load('./images/scene_right.jpeg');
  materials.push(new THREE.MeshBasicMaterial({ map: texture_right }));

  var texture_top = new THREE.TextureLoader().load('./images/scene_top.jpeg');
  materials.push(new THREE.MeshBasicMaterial({ map: texture_top }));

  var texture_bottom = new THREE.TextureLoader().load('./images/scene_bottom.jpeg');
  materials.push(new THREE.MeshBasicMaterial({ map: texture_bottom }));

  var texture_front = new THREE.TextureLoader().load('./images/scene_front.jpeg');
  materials.push(new THREE.MeshBasicMaterial({ map: texture_front }));

  var texture_back = new THREE.TextureLoader().load('./images/scene_back.jpeg');
  materials.push(new THREE.MeshBasicMaterial({ map: texture_back }));



  var box = new THREE.Mesh(
    new THREE.BoxGeometry(1, 1, 1),
    materials //材质
  )

  scene.add(box)

}

function loop() {
  requestAnimationFrame(loop)
  renderer.render(scene, camera)
}